﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 学生管理
{
    public partial class FormStudent : Form
    {
        public Button lightbuton;

        public FormStudent()
        {
            InitializeComponent();
        }

        public void ShowForm(Form form)//对右边panel的显示设定
        {
            foreach(Control fb in this.Pl_show.Controls)
            {
                if(fb is Form)
                {
                    ((Form)fb).Close();//关闭之前打开的文件
                }
            }
            this.Pl_show.Controls.Clear();//清除panel内的所有控件
            form.TopLevel = false;//将该子窗设为非顶级控件
            form.FormBorderStyle = FormBorderStyle.None;//去掉边框
            form.Dock = DockStyle.Fill;//子窗体随容器大小自动调整
            form.Parent = this.Pl_show;//设置父容器为当前窗口
            form.Show();

        }

       public void Setbutton(Button btn)//设置高亮button
        {
            foreach(Control c in panel1.Controls)
            {
                Button b = c as Button;
                if(null != b)
                {
                b.BackColor = Color.FromArgb(60, 179, 113);//背景变成与panel一样
                b.ForeColor = Color.FromArgb(255, 255, 255);//字体颜色复原
                b.TextAlign = ContentAlignment.MiddleCenter;//字体中对齐
                b.FlatAppearance.MouseOverBackColor = Color.FromArgb(0,250,154);//鼠标停留时颜色
                }
                
            }

            //当选中某button时
            if(btn != null)
            {
                btn.BackColor = Color.FromArgb(240, 240, 240);//背景变成与Pt_show一样
                btn.ForeColor = Color.FromArgb(60, 170, 113);//字体颜色变亮
                btn.TextAlign = ContentAlignment.MiddleRight;//字体右对齐
                btn.FlatAppearance.MouseOverBackColor = Color.FromArgb(220, 250, 230);//鼠标停留时颜色
            }
        }
       
        public void PictureSide(Button button)//button边缘圆角的设定
        {

            int y = button.Top;
            Pb1.Location = new System.Drawing.Point(0, y-8);
            Pb2.Location = new System.Drawing.Point(0,y);
            Pb1.Visible = true;
            Pb2.Visible = true;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form form = new FormInformation();
            ShowForm(form);
            Setbutton(this.button1);
            PictureSide(button1);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form form = new FormSubject();
            ShowForm(form);
            Setbutton(this.button2);
            PictureSide(button2);
        }

        private void Pl_show_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}
